#include "Rp2VertexShader.h"
#include "Rp2Catalog.h"

using namespace Rp2;

RP2_IMPLEMENT_RTTI(Rp2, VertexShader, Shader);
RP2_IMPLEMENT_DEFAULT_NAME_ID(VertexShader, Shader);

//---------------------------------------------------------------------------------------------------
VertexShader::VertexShader(const std::string& rkShaderName)
	:
	Shader(rkShaderName)
{
    m_spkProgram = Catalog<VertexProgram>::GetActive()->Find(rkShaderName);
    if (!m_spkProgram )
    {
        // Use the default vertex program when the requested program
        // cannot be found.
        m_spkProgram = Catalog<VertexProgram>::GetActive()->Find("Default");

        // In release builds, if the default vertex program cannot be found,
        // you probably have placed the shader programs in a place that
        // is not stored in the System directory lists.
        assert(m_spkProgram);
    }

    if (m_spkProgram)
    {
        OnLoadProgram();
    }
}
//---------------------------------------------------------------------------------------------------
VertexShader::~VertexShader()
{
}
//---------------------------------------------------------------------------------------------------
void VertexShader::SetShader(const std::string& rkShaderName)
{
	m_kShaderName = rkShaderName;

    m_spkProgram = Catalog<VertexProgram>::GetActive()->Find(rkShaderName);
    if (!m_spkProgram )
    {
        // Use the default vertex program when the requested program
        // cannot be found.
        m_spkProgram = Catalog<VertexProgram>::GetActive()->Find("Default");

        // In release builds, if the default vertex program cannot be found,
        // you probably have placed the shader programs in a place that
        // is not stored in the System directory lists.
        assert(m_spkProgram);
    }

    if (m_spkProgram)
    {
        OnLoadProgram();
    }
}
//---------------------------------------------------------------------------------------------------
VertexProgram* VertexShader::GetProgram() const
{
	return StaticCast<VertexProgram>(m_spkProgram);
}
//---------------------------------------------------------------------------------------------------